<?php
namespace Admin\Controller;
use Think\Controller;
/**
 * 公共 Action 类
 * @author Jeff
 */
class InstrumentController extends CommonController {

    public function index() {
        $this->display();
    }
	public function instru_list(){
		$instrus = M('instruments');
		$count = $instrus->count();
		$Page   = new \Think\Page($count,4);
		$show   = $Page->show();
		$instru = $instrus->order(' id desc ')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('instru',$instru);
        $this->assign('page',$show);
		$this->display();
	}
	public function instru_add(){
		$this->display();
	}
	/**
	 * 增加与修改乐器
	 */
	public function instru_save(){
		if(IS_POST){
			$upload = get_upload_img(C('INSTRUMENT'));
			$imgurl = $upload['imgurl'];
			$savename = $imgurl['savename'];
			if($upload){//有上传图片
				$x = I('dataX');
				$y = I('dataY');
				$w = I('dataWidth');
				$h = I('dataHeight');
				$pre_imgurl = C('INSTRUMENT').$imgurl['savepath'].'/'.$imgurl['savename'];//未剪切的图片位置
				$savepath = C('INSTRUMENT');
				get_and_cut_upload_img($pre_imgurl,$savepath,$savename,$x,$y,$w,$h);//剪切图片并保存剪切图片
				$_POST['imgurl'] = C('TEAL_INSTRUMENT').$savename;//保存图片绝对路径
			}
			if($_POST['id']){
					if(M('instruments')->save($_POST)){
					$this->redirect('instru_list');
					}else{
					$this->error('您根本就没修改此乐器！');
				}
				$this->redirect('instru_list');
			}else{
				if(M('instruments')->add($_POST)){
					$this->redirect('instru_list');
				}else{
					$this->error('添加失败，请联系程序猿！');
				}
				$this->redirect('instru_add');
			}
		}
	}
	
	
	/**
     *  乐器信息
     *  @author xx
     */
    public function instru_info() {
    	$id = I('id');
		$instruments = M('instruments');
    	if($id){
    		$instru = $instruments->find($id);
			$this->assign('instru',$instru);
        	$this->display();
		}
    }
	
	 
	 /**
	  * 删除乐器
	  */
	  public function instru_delect(){
	  	$id = I('id');
	  	if($id){
	  		if(M('instruments')->delete($id)){
	  			$this->success('删除成功');
	  		}
		}
	  }
}